import common
import unittest

names = (
    ("Matt Kromer", 1),
    ("Jens Vagelpohl", 2),
    ("Chris Petrilli", 3)
    )

class test_basics(common.TestCase):

    tables_to_drop = ('test',)
    
    def test_basics(self):
        c = self.c

        c.execute("create table test ( name varchar2(64), id number(9) )")

        # Inserting into test
        c.executemany("insert into test (name, id) values (:1, :2)", names)

        # Selecting from test
        c.execute("select * from test")

        # Describing test
        self.assertEqual(list(c.description),
                         [('NAME', 'VARCHAR2', 64, 64, 0, 0, 1),
                          ('ID', 'NUMBER', 22, 22, 9, 0, 1)])
        c.arraysize = 20

        # Checking test
        
        self.assertEqual(c.fetchall(),
                         [['Matt Kromer', 1],
                          ['Jens Vagelpohl', 2],
                          ['Chris Petrilli', 3]])

        # Commiting test
        self.db.commit()

        # Adding one more entry
        c.execute("insert into test (name, id) values (:1, :2)", "Fred Flintstone", 4)

        # re-checking test
        c.execute("select * from test")
        self.assertEqual(c.fetchall(),
                         [['Matt Kromer', 1],
                          ['Jens Vagelpohl', 2],
                          ['Chris Petrilli', 3],
                          ['Fred Flintstone', 4]])

        # rolling back last entry"
        self.db.rollback()

        # checking test yet again
        c.execute("select * from test")
        self.assertEqual(c.fetchall(),
                         [['Matt Kromer', 1],
                          ['Jens Vagelpohl', 2],
                          ['Chris Petrilli', 3]])

if __name__ == '__main__':
    unittest.main()
